<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="urlList"
		:disabled="disabled"
		:isRequest="isRequest"
    @getDetail="getDetail"
		searchPlaceholder="请输入任务说明"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">业务分类编码</view>
          <view class="rl">{{ item.categoryCode }}</view>
        </view>
        <view class="option">
          <view class="lf">业务分类名称</view>
          <view class="rl">{{ item.categoryName }}</view>
        </view>
        <view class="option">
          <view class="lf">合同占比(%)</view>
          <view class="rl">{{ item.contractRate }}</view>
        </view>
        <view class="option">
          <view class="lf">分配合同额(元)</view>
          <view class="rl">{{ item.contractAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">生产团队</view>
          <view class="rl">{{ item.productTeam_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">团队负责人</view>
          <view class="rl">{{ item.teamLeader_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">任务说明</view>
          <view class="rl">{{ item.taskDescription }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { relationTaskList } from '@/api/index.js'
import { relationTaskInfo } from '@/api/index.js'
export default {
  name: 'HSelectProjectInputPopup',
  data() {
    return {
      params: {
				column: 'createTime',
				order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    api: {
      type: Function,
      default: relationTaskList,
    },
		disabled: {
			type: Boolean,
			required: false,
			default: false,
		},
		open: {
			type: Boolean,
			required: false,
			default: false,
		},
		multi: {
			type: Boolean,
			default: false,
			required: false,
		},
		props: {
			type: Object,
			default: null,
		},
		projectId: {
			type: [Number, String],
			default: '',
		},
		distributionType: {
			type: [Number, String],
			default: '',
		},
		// 第一次是否请求
		isRequest: {
		  type: Boolean,
		  default: true,
		},
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
		urlList () {
			return relationTaskList
		},
    queryParams() {
			const params = {
			  ...this.params,
			}
			if (this.keywords) {
			  params.taskDescription = '*' + this.keywords + '*'
			}
      if (this.projectId) {
        params.projectId = this.projectId
      }
			if (this.distributionType) {
        params.distributionType = this.distributionType
      }
      return params
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      relationTaskInfo({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.categoryName
          this.$emit('select', {
            data: res.result,
            id: value,
          })
        }
      })
    }
  },
}
</script>

<style lang="scss" scoped>
// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
